import { request } from "./request"

// 获取用户频道
export const getUserChannels = () => {
  return request({
    method: 'GET',
    url: "/app/v1_0/user/channels"
  })
}

// 全部频道
export const getAllChannels = () => {
  return request({
    method: "GET",
    url: "/app/v1_0/channels"
  })
}

// 批量修改用户频道列表（部分覆盖）
export const addUserChannels = (data) => {
  return request({
    method: "PATCH",
    url: "/app/v1_0/user/channels",
    data
  })
}

// 批量删除用户频道列表（部分覆盖）
export const deleteUserChannels = (target) => {
  return request({
    method: "DELETE",
    url: `/app/v1_0/user/channels/${target}`,
  })
}

// 联想建议
export const getSuggestion = (q) => {
  return request({
    method: "GET",
    url: "/app/v1_0/suggestion",
    params: {
      q
    }
  })
}

// 获取搜索结果
export const getSearchResult = (params) => {
  return request({
    method: "GET",
    url: "/app/v1_0/search",
    params
  })
}

// 获取用户搜索历史
export const getSearchHistories = () => {
  return request({
    method: "GET",
    url: "/app/v1_0/search/histories",
  })
}

// 删除用户搜索历史
export const deleteSearchHistories = () => {
  return request({
    method: "DELETE",
    url: "/app/v1_0/search/histories"
  })
}

// 获取新闻文章详情
export const getArticleById = articleId => {
  return request({
    method: 'GET',
    url: `/app/v1_0/articles/${articleId}`
  });
};

// 个人资料
export const getUserProfile = () => {
  return request({
    method: 'GET',
    url: `/app/v1_0/user/profile`
  });
};

// 编辑个人资料
export const updateUserProfile = () => {
  return request({
    method: 'PATCH',
    url: `/app/v1_0/user/profile`
  });
};

// 修改头像
export const updateUserPhoto = (data) => {
  return request({
    method: 'PATCH',
    url: `/app/v1_0/user/photo`,
    data
  });
};

// 关注用户
export const addUserFollowings = (userId) => {
  return request({
    method: "POST",
    url: "/app/v1_0/user/followings",
    data: {
      target: userId
    }
  })
}

// 取消关注用户
export const deteleUserFollowings = (target) => {
  return request({
    method: "DELETE",
    url: `/app/v1_0/user/followings/${target}`
  })
}

// 收藏文章
export const addCollections = (articleId) => {
  return request({
    method: "POST",
    url: "/app/v1_0/article/collections",
    data: {
      target: articleId
    }
  })
}

// 取消收藏
export const deleteCollection = (target) => {
  return request({
    method: "DELETE",
    url: `/app/v1_0/article/collections/${target}`
  })
}

/**
 * 评论
 * @param {*} type 评论类型，a-对文章(article)的评论，c-对评论(comment)的回复
 * @param {*} source 源id，文章id或评论id
 * @param {*} offset 获取评论数据的偏移量，值为评论id，表示从此id的数据向后取，不传表示从第一页开始读取数据
 * @param {*} limit 获取的评论数据个数，不传表示采用后端服务设定的默认每页数据量  
 */
export const getComments = (params) => {
  return request({
    method: "GET",
    url: "/app/v1_0/comments",
    params
  })
}

// 对文章点赞
export const addLikings = (art_id) => {
  return request({
    method: "POST",
    url: "/app/v1_0/article/likings",
    data: {
      target: art_id
    }
  })
}

// 取消文章点赞
export const deleteLikings = (target) => {
  return request({
    method: "DELETE",
    url: `/app/v1_0/article/likings/${target}`
  })
}